package org.example.config;

import org.example.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类，用于注册拦截器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
//    @Autowired
//    private DemoInterceptor demoInterceptor;
    @Autowired
    private TokenInterceptor tokenInterceptor;

    /**
     * /*: (一级路径) 能匹配/depts，/emps，/login，不能匹配 /depts/
     * /**: (任意级路径) 能匹配/depts，/depts/1，/depts/1/2
     * /depts/*:  能匹配/depts下的一级路径 能匹配 /depts/1，不能匹配 /depts/1/2，/depts
     * /depts/**: 能匹配/depts下的任意级路径 能匹配 /depts，/depts/1,/depts/1/2，不能匹配/emps/1
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")//拦截所有请求
                .excludePathPatterns("/login");//放行登录请求
    }
}
